/*整理接口,2017/07/26, author:lanlan.zeng*/
//登录获取token
function victoria_login(account,password,success, fail){

    var mobileReg = /^[1][3-8]\d{9}$/;
    var emailReg = /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;

    var loginDTO = {};

    debugAlert(account);
    if(account == null || account == ""){
        errorAlert("账号不能为空");
        return false;
    }

    if (password == null || password == ""){
        errorAlert("密码不能为空");
        return false;
    }

    loginDTO.pwd = hex_md5(password + "{cloud}");

    if(account != null && account != "") {
        if(account.match(mobileReg)){
            loginDTO.mobile = account;
        } else if (account.match(emailReg)){
            loginDTO.email = account;
        } else {
        	loginDTO.mobile = account;//lanlan.zeng 用户名含有字母归于mobile
        }
    } else {
        errorAlert("账号不能为空");
        return false;
    }

    doGet("/victoria/token.json", loginDTO, success, fail);
}

//修改密码
function victoria_modifyPwd(pwd,newPwd,newPwd2,success, fail) {
    var reg = /^[1][3-8]\d{9}$/;

    var modifyPwdDTO = {};

    addTokenToDTO(modifyPwdDTO);

    modifyPwdDTO.pwd = hex_md5(pwd + "{cloud}");
    modifyPwdDTO.new_pwd = hex_md5(newPwd + "{cloud}");

    doPut("/victoria/updatepwd.json",modifyPwdDTO,success, fail);
}

//判断治疗师,治疗师不能登录
function victoria_is_therapist_login_Syn(userName,success, fail){
    
    var dto = {};
    dto.login_account = userName;
    doGetSyn("/victoria/check_PC_login_auth.json",dto, success, fail);
}








/***********************无用接口********************************/
/*function victoria_getMobileCode(mobile,local,type,success, fail){

    var reg = /^[1][3-8]\d{9}$/;

    var registerDTO = {};

    debugAlert(mobile);
    if(mobile == null || mobile == ""){
        alert("手机号码不能为空");
        return false;
    }

    if(!mobile.match(reg)){
        alert("手机号输入错误");
        return false;
    }

    registerDTO.mobile = mobile;
    registerDTO.type = type;
    if(local != null) {
        registerDTO.local = local;
    }

    doGet("/victoria/mobile_code.json", registerDTO, success, fail);
}

function victoria_getRegisterMobileCode(mobile,local,success, fail) {
    victoria_getMobileCode(mobile,local,"registration",success, fail);
}

function victoria_getRsetPwdMobileCode(mobile,local,success, fail) {
    victoria_getMobileCode(mobile,local,"forgetpwd",success, fail);
}

function victoria_getModifyFirstMobileCode(mobile,local,success,fail) {
    victoria_getMobileCode(mobile,local,"modifyfirst",success,fail);
}

function victoria_getModifySecondMobileCode(mobile,local,success,fail) {
    victoria_getMobileCode(mobile,local,"modifysecond",success,fail);
}

function victoria_register(mobile,code,pwd,pwd2,success, fail) {
    var reg = /^[1][3-8]\d{9}$/;

    var registerDTO = {};

    debugAlert(mobile);
    if(mobile == null || mobile == ""){
        errorAlert("手机号码不能为空");
        alert("手机号码不能为空");
        return false;
    }

    if(!mobile.match(reg)){
        errorAlert("手机号输入错误");
        alert("手机号输入错误");
        return false;
    }

    if(code == null || code == "") {
        errorAlert("验证码不能为空");
        alert("验证码不能为空");
        return false;
    }

    if (pwd == null || pwd ==""){
        errorAlert("密码不能为空");
        alert("密码不能为空");
        return false;
    }

    if (pwd.length < 6){
        errorAlert("密码不能少于6位");
        alert("密码不能少于6位");
        return false;
    }

    if(pwd != pwd2) {
        errorAlert("密码输入不一致");
        alert("密码输入不一致");
        return false;
    }

    registerDTO.mobile = mobile;
    registerDTO.code = code;
    registerDTO.pwd = hex_md5(pwd + "{cloud}");

    doPost("/victoria/register.json",registerDTO,success, fail);
}

function victoria_forgetPwd(mobile,code,newPwd,newPwd2,success, fail) {
    var reg = /^[1][3-8]\d{9}$/;

    var forgetPwdDTO = {};

    if(mobile == null || mobile == ""){
        errorAlert("手机号码不能为空");
        return false;
    }

    if(!mobile.match(reg)){
        errorAlert("手机号输入错误");
        return false;
    }

    if(code == null || code == "") {
        errorAlert("验证码不能为空");
        return false;
    }

    if(newPwd != newPwd2) {
        errorAlert("密码输入不一致");
        return false;
    }

    forgetPwdDTO.mobile = mobile;
    forgetPwdDTO.code = code;
    forgetPwdDTO.new_pwd = hex_md5(newPwd + "{cloud}");

    doPost("/victoria/forgetpwd.json",forgetPwdDTO,success, fail);
}*/



function victoria_logout(success, fail) {

    var logoutDTO = {};
    addTokenToDTO(logoutDTO);

    /*if(token == null || token == "") {
        errorAlert("需要登陆");
        return false;
    }*/

    doDelete("/victoria/token.json",logoutDTO,success, fail);
}

/*function victoria_modify_first(old_mobile,old_email,code,success,fail){
    var oldAccountDTO={};
    oldAccountDTO.mobile=old_mobile;
    oldAccountDTO.email=old_email;
    oldAccountDTO.code=code;
    doGet("/victoria/modify_first.json",oldAccountDTO,success,fail);
}

function victoria_update_account(new_mobile,new_email,old_account,code,first_code,success,fail){
    var accountDTO={};
    accountDTO.mobile=new_mobile;
    accountDTO.email=new_email;
    accountDTO.account=old_account;
    accountDTO.code=code;
    accountDTO.first_code=first_code;
    doPut("/victoria/update_account.json",accountDTO,success,fail);
}*/